package com.leco.exam.controller;

import com.leco.exam.domain.req.QuestionQueryWebRequest;
import com.leco.exam.topic.biz.entity.Question;
import com.leco.exam.topic.biz.service.QuestionService;
import com.leco.exam.webcommon.common.Response;
import com.leco.exam.webcommon.common.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author greg
 * @version 2022/9/8
 **/
@RestController
@RequestMapping("/question")
@CrossOrigin(origins = "*", maxAge = 3600) // todo 临时的跨域方案，后面改成nginx反向代理
public class QuestionController {
    @Autowired
    private QuestionService questionService;

    @GetMapping("/{id}")
    public ResponseData<Question> getById(@PathVariable Integer id) {
        return Response.ok(questionService.getById(id));
    }

    @GetMapping
    public ResponseData<List<Question>> list(@Valid QuestionQueryWebRequest webRequest) {
        return Response.ok(questionService.listByTopicId(webRequest.getTopicId()));
    }


}
